//用于生成和解析token
var jwt = require('jsonwebtoken')
var signKey = 'mes_qdhd_mobile_xhykjyxgs'

const tokenFn = {
  setToken: function (username, password) {
    return new Promise((resolve, reject) => {
      const token = jwt.sign({
        username: username,
        password: password
      }, signKey, { expiresIn: '24h' })
      resolve(token)
    })
  },
  verToken: function (token) {
    return new Promise((resolve, reject) => {
      var info = jwt.verify(token.split(' ')[1], signKey)
      resolve(info)
    })
  }
}

module.exports = tokenFn